#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 40;
int n, g[N][N];
bool vis[N][N];
int dx[] = { -1,1,0,0 };
int dy[] = { 0,0,-1,1 };

struct node {
	int x, y;
};
queue<node> q;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cin >> g[i][j];
		}
	}
	vis[0][0] = 1;
	q.push({ 0,0 });
	while (!q.empty()) {
		node p = q.front(); q.pop();
		for (int i = 0; i < 4; i++) {
			int nx = p.x + dx[i], ny = p.y + dy[i];
			if (nx<0 || nx>n + 1 || ny<0 || ny >> n + 1) continue;
			if (!vis[nx][ny] && g[nx][ny] == 0) {
				vis[nx][ny] = 1;
				q.push({ nx,ny });
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (g[i][j] == 1) cout << 1 << " ";
			if (g[i][j] == 0 && !vis[i][j]) cout << 2 << " ";
			if (g[i][j] == 0 && vis[i][j]) cout << 0 << " ";
		}
		cout << endl;
	}
	return 0;
}